#include <stdio.h>
#include <signal.h>
#include <unistd.h>

int main()
{
    sigset_t old_mask, new_mask;
    int ret;

    sigemptyset(&new_mask);
    sigaddset(&new_mask, SIGINT);
    ret = sigprocmask(SIG_BLOCK, &new_mask, NULL);
    if (ret == -1)
    {
        perror("sigprocmask");
        return 1;
    }

    printf("SIGINT has been blocked. Send Ctrl+C to generate SIGINT\n");
    sleep(5);

    ret = sigprocmask(SIG_BLOCK, NULL, &old_mask);
    if (ret == -1)
    {
        perror("sigprocmask SIG_BLOCK");
        return 1;
    }

    printf("\nBefore unblocking, the blocked signals are: ");
    for (int i = 1; i < NSIG; i++)
    {
        if (sigismember(&old_mask, i))
        {
            printf("%d ", i);
        }
    }
    printf("\n");

    ret = sigprocmask(SIG_UNBLOCK, &new_mask, NULL);
    if (ret == -1)
    {
        perror("sigprocmask SIG_UNBLOCK");
        return 1;
    }

    printf("SIGINT has been unblocked. Sending SIGINT now\n");
    return 0;
}